﻿using System;
using System.Collections.Generic;
using NakedObjects;
using NakedObjects.Value;

namespace HRMDomain
{
    public class Performance:Base
    {

        [Hidden]
        public virtual Employee Employee { get; set; }
        [Mask("d")]
        public virtual DateTime Date { get; set; }
        public virtual PerformanceCategory Category { get; set; }
        [MultiLine]
        public virtual string Details { get; set; }
        public virtual PerformanceOutcome Outcome { get; set; }
        public virtual DateTime? ReviewDate { get; set; }
        public virtual bool Finalised { get; set; }


        public string Title()
        {
            TitleBuilder t = new TitleBuilder();
            t.Append(Date.ToShortDateString()).Append(Category.Name);
            return t.ToString();
        }


        #region Meetings (collection)
        private ICollection<Meeting> _Meetings = new List<Meeting>();

        public virtual ICollection<Meeting> Meetings
        {
            get
            {
                return _Meetings;
            }
            set
            {
                _Meetings = value;
            }
        }
        #endregion
        #region Notes (collection)
        private ICollection<Note> _Notes = new List<Note>();

        public virtual ICollection<Note> Notes
        {
            get
            {
                return _Notes;
            }
            set
            {
                _Notes = value;
            }
        }
        #endregion

        #region AddNote (Action)

        [MemberOrder(Sequence = "1")]
        public void AddNote([MultiLine]string Entry)
        {
            Note newNote = Container.NewTransientInstance<Note>();

            newNote.EnteredDate = DateTime.Now;
            newNote.Text = Entry;
            Container.Persist<Note>(ref newNote);
            if (!(_Notes.Contains(newNote)))
            {
                _Notes.Add(newNote);
            }
            Container.InformUser("New Note Added.");

        }

        // Use 'hide', 'dis', 'val', 'actdef', 'actcho' shortcuts to add supporting methods here.
        #endregion
        #region AddMeeting (Action)

        [MemberOrder(Sequence = "2")]
        public void AddMeeting(DateTime DatePerformed)
        {
            Meeting newMeeting = Container.NewTransientInstance<Meeting>();

            newMeeting.DatePerformed = DateTime.Now;
            Container.Persist<Meeting>(ref newMeeting);
            if (!(_Meetings.Contains(newMeeting)))
            {
                _Meetings.Add(newMeeting);
            }
            Container.InformUser("New Meeting Added.");

        }

        // Use 'hide', 'dis', 'val', 'actdef', 'actcho' shortcuts to add supporting methods here.
        #endregion

        #region Documents (collection)
        private ICollection<Document> _Documents = new List<Document>();

        public virtual ICollection<Document> Documents
        {
            get
            {
                return _Documents;
            }
            set
            {
                _Documents = value;
            }
        }
        #endregion
        #region AddDocument (Action)

        [MemberOrder(Sequence = "1")]
        public void AddDocument(string Name, FileAttachment file)
        {
            Document newdoc = Container.NewTransientInstance<Document>();
            newdoc.Name = Name;
            newdoc.Data = file.GetResourceAsByteArray();
            newdoc.MIMEType = file.MimeType;

            Container.Persist<Document>(ref newdoc);

            Documents.Add(newdoc);
            Container.InformUser("Document Attachment Added.");

        }

        // Use 'hide', 'dis', 'val', 'actdef', 'actcho' shortcuts to add supporting methods here.
        #endregion
    }
}
